#!/usr/bin/perl
use strict;
package nswhois;

sub nswhois {
    my ($dbh,$remote,$nsnum,$input) = @_;
    my $sth;
$sth=$dbh->prepare("SELECT nick,auth,host,oper,server FROM ninfo WHERE nick = '$$input[4]';");
$sth->execute; 
    my @result = $sth->fetchrow_array;
    if ($$input[4] eq "") {
	print $remote "$nsnum O $$input[0] :Syntax :WHOIS <nick>\n";
    }
    elsif ($result[0] eq "") {
	print $remote "$nsnum O $$input[0] :$$input[4] is \cBNOT\cB online.\n";
    }
    elsif ($result[1] eq '0') {
	print $remote "$nsnum O $$input[0] :$$input[4] \[$result[2]\] has \cBNOT\cB been identified.\n";
	if ($result[3]) {
	    print $remote "$nsnum O $$input[0] :$$input[4] is an Oper on $result[4].\n";
	}
    }
    else {
	print $remote "$nsnum O $$input[0] : $$input[4] \[$result[2]\] has been identified as \cB$result[1]\cB\n";
	$sth=$dbh->prepare("SELECT cslvl FROM nicks WHERE rnick = '$result[1]';");
	$sth->execute;
	my $result = $sth->fetchrow_array;
	if ($result) {
	    print $remote "$nsnum O $$input[0] :$$input[4] is a Services Operator.\n";
	}
	elsif ($result[3]) {
	    print $remote "$nsnum O $$input[0] :$$input[4] is an Oper on $result[4].\n";
	}
	undef $result;
    }
    undef @result;

}
1;
